package collection;

import java.util.*;

public class SortPoint {
    public static void main(String[] args) {
        List<Point> a = new ArrayList<>();
        a.add(new Point(1,2));
        a.add(new Point(30,415));
        a.add(new Point(15,56));
        a.add(new Point(7,8));
        a.add(new Point(9,10));
        a.add(new Point(-11,12));
        System.out.println("排序前："+a);
        Collections.sort(a, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                int a1 = o1.getX()*o1.getX() + o1.getY()* o1.getY();
                int a2 = o2.getX()*o2.getX() + o2.getY()* o2.getY();
                return a1 - a2;
            }
        });
        //Lambda表达式简化
        //Collections.sort(a, (o1,o2) -> o1.getX()*o1.getX() + o1.getY()* o1.getY() - o2.getX()*o2.getX() + o2.getY()* o2.getY());
        System.out.println("升序排序后："+a);

    }
}
